//
//  CLDiscoverView.swift
//  CLWeibo
//
//  Created by 陈亮 on 16/7/12.
//  Copyright © 2016年 陈亮. All rights reserved.
//

import UIKit

class CLDiscoverView: UIView,UITextFieldDelegate {
    @IBOutlet weak var cancelButton: UIButton!

    @IBOutlet weak var searchTexeField: UITextField!
    
    @IBOutlet weak var texeFieldRight: NSLayoutConstraint!
    
    // MARK:  加载xib
    class func searchView ()->CLDiscoverView {
        return UINib(nibName: "CLDiscoverView", bundle: nil).instantiateWithOwner(nil , options: nil).last! as! CLDiscoverView
    }
    
    
    //取消按钮点击事件
    @IBAction func cancelAction(sender: AnyObject) {
        
        //取消第一响应者 收回键盘
        searchTexeField.resignFirstResponder()
        //右边间距
        texeFieldRight.constant = 0
        //设置动画
       UIView.animateWithDuration(0.3) { () -> Void in
        self.layoutIfNeeded()
        }
    }
    
    
    // MARK: -- UITextFieldDelegate 代理
    
    
    func textFieldDidBeginEditing(textField: UITextField) {
        
        texeFieldRight.constant = cancelButton.width
        
        UIView.animateWithDuration(0.25) { () -> Void in
            self.layoutIfNeeded()
        }
        
        
    }
    
    
}
